<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="丈夫姓氏" prop="manSurname">
        <el-input
          v-model="queryParams.manSurname"
          placeholder="请输入丈夫姓氏"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="丈夫姓氏ID" prop="manSurnameId">
        <el-input
          v-model="queryParams.manSurnameId"
          placeholder="请输入丈夫姓氏ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="妻子姓氏" prop="wmanSurname">
        <el-input
          v-model="queryParams.wmanSurname"
          placeholder="请输入妻子姓氏"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="妻子姓氏ID" prop="wmanSurrnameId">
        <el-input
          v-model="queryParams.wmanSurrnameId"
          placeholder="请输入妻子姓氏ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否婚配" prop="isMarry">
        <el-select v-model="queryParams.isMarry" placeholder="请选择是否婚配" clearable>
          <el-option
            v-for="dict in dict.type.isMarry"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
     <!-- <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="父亲姓氏" prop="fatherName">
        <el-input
          v-model="queryParams.fatherName"
          placeholder="请输入父亲姓氏"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="母亲姓氏" prop="motherName">
        <el-input
          v-model="queryParams.motherName"
          placeholder="请输入母亲姓氏"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="告警等级" prop="warningLevel">
        <el-input
          v-model="queryParams.warningLevel"
          placeholder="请输入告警等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.orderStatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="支付金额" prop="payPrice">
        <el-input
          v-model="queryParams.payPrice"
          placeholder="请输入支付金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付类型" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付类型" clearable>
          <el-option
            v-for="dict in dict.type.payType"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="退款金额" prop="refundPrice">
        <el-input
          v-model="queryParams.refundPrice"
          placeholder="请输入退款金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退款原因" prop="refundDesc">
        <el-input
          v-model="queryParams.refundDesc"
          placeholder="请输入退款原因"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专家意见" prop="expertOpinion">
        <el-input
          v-model="queryParams.expertOpinion"
          placeholder="请输入专家意见"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
       <el-form-item label="时间" prop="biliTime">
              <el-date-picker clearable
                v-model="queryParams.biliTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择时间">
              </el-date-picker>
            </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yh:bingli:add']"
        >新增</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yh:bingli:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yh:bingli:remove']"
        >删除</el-button>
      </el-col>
   <!--   <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yh:bingli:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bingliList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="丈夫姓氏" align="center" prop="manSurname" />
      <el-table-column label="丈夫姓氏ID" v-if="false" align="center" prop="manSurnameId" />
      <el-table-column label="丈夫照片" align="center" prop="manSurnameImage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.manSurnameImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="妻子姓氏" align="center" prop="wmanSurname" />
      <el-table-column label="妻子姓氏ID" v-if="false" align="center" prop="wmanSurrnameId" />
      <el-table-column label="妻子照片" align="center" prop="wmanSurrnameImage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.wmanSurrnameImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="是否婚配" align="center" prop="isMarry">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.isMarry" :value="scope.row.isMarry"/>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="父亲姓氏" align="center" prop="fatherName" />
      <el-table-column label="母亲姓氏" align="center" prop="motherName" />
      <el-table-column label="疾病类型" align="center" prop="diseaseType" />
      <el-table-column label="病情描述" v-if="false" align="center" prop="diseaseDesc" />
      <el-table-column label="告警等级" align="center" prop="warningLevel" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.orderStatus" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="订单编号" align="center" prop="orderNo" />
      <el-table-column label="支付金额" align="center" prop="payPrice" />
      <el-table-column label="支付类型" align="center" prop="payType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.payType" :value="scope.row.payType"/>
        </template>
      </el-table-column>
      <el-table-column label="退款金额" align="center" prop="refundPrice" />
      <el-table-column label="退款原因" v-if="false" align="center" prop="refundDesc" />
      <el-table-column label="专家意见" align="center" v-if="false" prop="expertOpinion" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yh:bingli:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yh:bingli:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改病例清单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="丈夫姓氏" prop="manSurname">
          <el-input v-model="form.manSurname" placeholder="请输入丈夫姓氏" />
        </el-form-item>
        <el-form-item label="丈夫姓氏ID" v-if="false" prop="manSurnameId">
          <el-input v-model="form.manSurnameId" placeholder="请输入丈夫姓氏ID" />
        </el-form-item>
        <el-form-item label="丈夫照片" >
          <image-upload v-model="form.manSurnameImage"/>
        </el-form-item>
        <el-form-item label="妻子姓氏" prop="wmanSurname">
          <el-input v-model="form.wmanSurname" placeholder="请输入妻子姓氏" />
        </el-form-item>
        <el-form-item label="妻子姓氏ID" v-if="false" prop="wmanSurrnameId">
          <el-input v-model="form.wmanSurrnameId" placeholder="请输入妻子姓氏ID" />
        </el-form-item>
        <el-form-item label="妻子照片">
          <image-upload v-model="form.wmanSurrnameImage"/>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sex"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否婚配" prop="isMarry">
          <el-select v-model="form.isMarry" placeholder="请选择是否婚配">
            <el-option
              v-for="dict in dict.type.isMarry"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="父亲姓氏" prop="fatherName">
          <el-input v-model="form.fatherName" placeholder="请输入父亲姓氏" />
        </el-form-item>
        <el-form-item label="母亲姓氏" prop="motherName">
          <el-input v-model="form.motherName" placeholder="请输入母亲姓氏" />
        </el-form-item>
        <el-form-item label="病情描述">
          <editor v-model="form.diseaseDesc" :min-height="192"/>
        </el-form-item>
        <el-form-item label="告警等级" prop="warningLevel">
          <el-input v-model="form.warningLevel" placeholder="请输入告警等级" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.orderStatus"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="支付金额" prop="payPrice">
          <el-input v-model="form.payPrice" placeholder="请输入支付金额" />
        </el-form-item>
        <el-form-item label="支付类型" prop="payType">
          <el-select v-model="form.payType" placeholder="请选择支付类型">
            <el-option
              v-for="dict in dict.type.payType"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="退款金额" prop="refundPrice">
          <el-input v-model="form.refundPrice" placeholder="请输入退款金额" />
        </el-form-item>
        <el-form-item label="退款原因" prop="refundDesc">
          <el-input v-model="form.refundDesc" placeholder="请输入退款原因" />
        </el-form-item>
        <el-form-item label="专家意见" prop="expertOpinion">
          <el-input v-model="form.expertOpinion" placeholder="请输入专家意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBingli, getBingli, delBingli, addBingli, updateBingli } from "@/api/yh/bingli";

export default {
  name: "Bingli",
  dicts: ['orderStatus', 'sex', 'payType', 'isMarry'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 病例清单表格数据
      bingliList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        manSurname: null,
        manSurnameId: null,
        manSurnameImage: null,
        wmanSurname: null,
        wmanSurrnameId: null,
        wmanSurrnameImage: null,
        sex: null,
        isMarry: null,
        age: null,
        fatherName: null,
        motherName: null,
        diseaseType: null,
        diseaseDesc: null,
        warningLevel: null,
        status: null,
        orderNo: null,
        payPrice: null,
        payType: null,
        refundPrice: null,
        refundDesc: null,
        expertOpinion: null,
        biliTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sex: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        isMarry: [
          { required: true, message: "是否婚配不能为空", trigger: "change" }
        ],
        diseaseType: [
          { required: true, message: "疾病类型不能为空", trigger: "change" }
        ],
        warningLevel: [
          { required: true, message: "告警等级不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询病例清单列表 */
    getList() {
      this.loading = true;
      listBingli(this.queryParams).then(response => {
        this.bingliList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        manSurname: null,
        manSurnameId: null,
        manSurnameImage: null,
        wmanSurname: null,
        wmanSurrnameId: null,
        wmanSurrnameImage: null,
        sex: null,
        isMarry: null,
        age: null,
        fatherName: null,
        motherName: null,
        diseaseType: null,
        diseaseDesc: null,
        warningLevel: null,
        status: null,
        orderNo: null,
        payPrice: null,
        payType: null,
        refundPrice: null,
        refundDesc: null,
        expertOpinion: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加病例清单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBingli(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改病例清单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBingli(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBingli(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除病例清单编号为"' + ids + '"的数据项？').then(function() {
        return delBingli(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yh/bingli/export', {
        ...this.queryParams
      }, `bingli_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
